function red() {
  console.log('red');
}
function green() {
  console.log('green');
}

function yellow() {
  console.log('yellow');
}
function flash(cb, timer) {
  return new Promise((resolve) => {
    setTimeout(cb, timer)
    resolve()
  })
}

function light() {
  return new Promise((resolve) => {
    setTimeout(function () {
      red()
      resolve()
    }, 3000)
  }).then(() => {
    setTimeout(function () {
      green()
    }, 2000)
  }).then(() => {
    setTimeout(function () {
      yellow()
      light()
    }, 1000)
  })
}
light()